﻿using System;
using System.Configuration;

namespace Alex.Library.Log.Configuration
{
    /// <summary>
    /// 控制台日志元素
    /// </summary>
    public sealed class ConsoleLoggerElement : LoggerElement
    {
        /// <summary>
        /// 控制台前景色元素
        /// </summary>
        [ConfigurationProperty("foregroundColor", IsRequired = false)]
        public ForegroundColorElement ForegroundColor
        {
            get
            {
                return (ForegroundColorElement)this["foregroundColor"];
            }
        }

        /// <summary>
        /// 根据配置获取控制台日志对象
        /// </summary>
        /// <returns></returns>
        public override ILogger GetLogger()
        {
            ConsoleLogger cl = new ConsoleLogger();
            cl.FlushLevel = this.FlushLevel.Value;
            cl.Template = this.Template.GetTemplate();
            cl.SetForegroundColor(LogLevel.DEBUG, this.ForegroundColor.Debug.Value);
            cl.SetForegroundColor(LogLevel.INFO, this.ForegroundColor.Info.Value);
            cl.SetForegroundColor(LogLevel.WARN, this.ForegroundColor.Warn.Value);
            cl.SetForegroundColor(LogLevel.ERROR, this.ForegroundColor.Error.Value);
            cl.SetForegroundColor(LogLevel.FATAL, this.ForegroundColor.Fatal.Value);
            return cl;
        }
    }
}
